﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
@section header{

}
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            表名称：<input id="tableName" name="TableName" type="text" />
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            @*<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:post:add">
                    <i class="fa fa-plus"></i> 新增
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:post:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:post:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:post:export">
                    <i class="fa fa-download"></i> 导出
                </a>*@
            @*<a id="btnSync" class="btn btn-primary" onclick="syncDatabase()"><i class="fa fa-edit"></i> 同步</a>*@
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable"></table>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        var options = {
            id: "gridTable",
            url: "/SystemManage/Database/GetTablePageListJson",
            createUrl: "",
            updateUrl: "",
            removeUrl: "",
            detailView: true,//显示子表
            sortName: "TableName",
            sortOrder: "asc",
            modalName: "数据",
            columns: [
                { checkbox: true, visible: true },
                { field: 'id', title: 'id', visible: false },
                { field: 'tableName', title: '表名称', sortable: true },
                { field: 'tableKeyName', title: '主键名称' },
                { field: 'tableKey', title: '主键字段' },
                { field: 'tableCount', title: '记录数' },
                { field: 'remark', title: '备注' }
            ],
            onClickRow: function (row, element) {
                // element[0].firstElementChild.firstElementChild.click();
                //勾选复选框 只在有父子表的时候使用
                $(element[0]).find("input").click();
                //执行点击事件   只在有父子表的时候使用
                var a = element[0].firstElementChild.firstElementChild;
                $(a).trigger('click');
            },
            onExpandRow: function (index, row, $detail) {
                initChildGrid(index, row, $detail);
            }
        };
        $.table.init(options);
    });
    //加载行表格
    function initChildGrid(index, row, $detail) {
        var queryUrl = '/SystemManage/Database/GetTableFieldListJson' + '?tableName=' + row.tableName;
        var cur_table = $detail.html('<div style="border:1px solid #666666"><table id="gridChildrenTable_' + index + '"></table></div>').find('table');
        $detail.css("padding-left", "28px");
        var options1 = {
            id: "gridChildrenTable_" + index,
            toolbar: '',
            url: queryUrl,
            pagination: false,
            showColumns: false,
            showRefresh: false,
            showToggle: false,
            showSearch: false,
            columns: [
                { field: 'tableColumn', title: '列名', width: 180 },
                { field: 'datatype', title: '数据类型', width: 180 },
                { field: 'fieldLength', title: '长度', width: 180 },
                { field: 'remark', title: '说明' }
            ]
        };
        $.table.init(options1);
    }

    function syncDatabase() {
        ys.ajax({
            url: '/SystemManage/Database/SyncDatabaseJson',
            type: "post",
            success: function (obj) {
                if (obj.code == 1000) {
                    ys.msgSuccess('同步完成');
                }
                else {
                    ys.msgError(obj.Message);
                }
            }
        });
    }
</script>
